<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: VGA/VIC20/VIC20.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_v_g_a_2_v_i_c20_2_v_i_c20_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">VGA/VIC20/VIC20.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>Commodore VIC20 Emulator</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2021 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Optional SD Card connections:</span></div><div class="line"><span class="comment"> *   MISO =&gt; GPIO 16  (2 for PICO-D4)</span></div><div class="line"><span class="comment"> *   MOSI =&gt; GPIO 17  (12 for PICO-D4)</span></div><div class="line"><span class="comment"> *   CLK  =&gt; GPIO 14</span></div><div class="line"><span class="comment"> *   CS   =&gt; GPIO 13</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * To change above assignment fill other paramaters of FileBrowser::mountSDCard().</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#pragma message &quot;This sketch requires Tools-&gt;Partition Scheme = Huge APP&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;Preferences.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;WiFi.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;HTTPClient.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabutils_8h.html">fabutils.h</a>&quot;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;src/machine.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// embedded (free) games</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/blue_star.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/omega_fury.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/quikman.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/splatform.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/demo_birthday.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/arukanoido.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/demo_bah_bah_final.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/demo_digit.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/dragonwing.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/kikstart.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/kweepoutmc.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/nibbler.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/pooyan.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/popeye.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/pulse.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/spikes.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/tank_battalion.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/tetris_plus.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/astro-panic.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/frogger07.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/froggie.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;progs/embedded/tammerfors.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// non-free list</span></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> *  LIST_URL    = <span class="stringliteral">&quot;http://cloud.cbm8bit.com/adamcost/vic20list.txt&quot;</span>;</div><div class="line">constexpr <span class="keywordtype">int</span> MAXLISTSIZE = 8192;</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Flash and SDCard configuration</span></div><div class="line"><span class="preprocessor">#define FORMAT_ON_FAIL     true</span></div><div class="line"><span class="preprocessor">#define SPIFFS_MOUNT_PATH  &quot;/flash&quot;</span></div><div class="line"><span class="preprocessor">#define SDCARD_MOUNT_PATH  &quot;/SD&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// base path (can be SPIFFS_MOUNT_PATH or SDCARD_MOUNT_PATH depending from what was successfully mounted first)</span></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> * basepath = <span class="keyword">nullptr</span>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// name of embedded programs directory</span></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> * EMBDIR  = <span class="stringliteral">&quot;Free&quot;</span>;</div><div class="line"></div><div class="line"><span class="comment">// name of downloaded programs directory</span></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> * DOWNDIR = <span class="stringliteral">&quot;List&quot;</span>;</div><div class="line"></div><div class="line"><span class="comment">// name of user directory (where LOAD and SAVE works)</span></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> * USERDIR = <span class="stringliteral">&quot;Free&quot;</span>;    <span class="comment">// same of EMBDIR</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>EmbeddedProgDef {</div><div class="line">  <span class="keywordtype">char</span> <span class="keyword">const</span> *    filename;</div><div class="line">  uint8_t <span class="keyword">const</span> * <a name="a0"></a><a class="code" href="displaycontroller_8h_a96db82e580e46e24e2b39dd6c5bf7c21.html#a96db82e580e46e24e2b39dd6c5bf7c21">data</a>;</div><div class="line">  <span class="keywordtype">int</span>             size;</div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Embedded programs</span></div><div class="line"><span class="comment">//   To convert a PRG to header file use...</span></div><div class="line"><span class="comment">//         xxd -i myprogram.prg &gt;myprogram.h</span></div><div class="line"><span class="comment">//   ...modify like files in progs/embedded, and put filename and binary data in following list.</span></div><div class="line"><span class="keyword">const</span> EmbeddedProgDef embeddedProgs[] = {</div><div class="line">  { arukanoido_filename, arukanoido_prg, <span class="keyword">sizeof</span>(arukanoido_prg) },</div><div class="line">  { nibbler_filename, nibbler_prg, <span class="keyword">sizeof</span>(nibbler_prg) },</div><div class="line">  { pooyan_filename, pooyan_prg, <span class="keyword">sizeof</span>(pooyan_prg) },</div><div class="line">  { popeye_filename, popeye_prg, <span class="keyword">sizeof</span>(popeye_prg) },</div><div class="line">  { tetris_plus_filename, tetris_plus_prg, <span class="keyword">sizeof</span>(tetris_plus_prg) },</div><div class="line">  { spikes_filename, spikes_prg, <span class="keyword">sizeof</span>(spikes_prg) },</div><div class="line">  { astro_panic_filename, astro_panic_prg, <span class="keyword">sizeof</span>(astro_panic_prg) },</div><div class="line">  { splatform_filename, splatform_prg, <span class="keyword">sizeof</span>(splatform_prg) },</div><div class="line">  { kweepoutmc_filename, kweepoutmc_prg, <span class="keyword">sizeof</span>(kweepoutmc_prg) },</div><div class="line">  { dragonwing_filename, dragonwing_prg, <span class="keyword">sizeof</span>(dragonwing_prg) },</div><div class="line">  { tank_battalion_filename, tank_battalion_prg, <span class="keyword">sizeof</span>(tank_battalion_prg) },</div><div class="line">  { blue_star_filename, blue_star_prg, <span class="keyword">sizeof</span>(blue_star_prg) },</div><div class="line">  { quikman_filename, quikman_prg, <span class="keyword">sizeof</span>(quikman_prg) },</div><div class="line">  { frogger07_filename, frogger07_prg, <span class="keyword">sizeof</span>(frogger07_prg) },</div><div class="line">  { tammerfors_filename, tammerfors_prg, <span class="keyword">sizeof</span>(tammerfors_prg) },</div><div class="line">  { pulse_filename, pulse_prg, <span class="keyword">sizeof</span>(pulse_prg) },</div><div class="line">  { omega_fury_filename, omega_fury_prg, <span class="keyword">sizeof</span>(omega_fury_prg) },</div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#if DEBUGMACHINE</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">volatile</span> <span class="keywordtype">int</span>  scycles = 0;</div><div class="line"><span class="keyword">static</span> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> restart = <span class="keyword">false</span>;</div><div class="line"><span class="keywordtype">void</span> vTimerCallback1SecExpired(xTimerHandle pxTimer)</div><div class="line">{</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;%d - &quot;</span>, scycles / 5);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Free memory (total, min, largest): %d, %d, %d\n&quot;</span>, heap_caps_get_free_size(0), heap_caps_get_minimum_free_size(0), heap_caps_get_largest_free_block(0));</div><div class="line">  restart = <span class="keyword">true</span>;</div><div class="line">}</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"></div><div class="line"><a name="_a1"></a><a class="code" href="classfabgl_1_1_v_g_a_controller.html">fabgl::VGAController</a> DisplayController;</div><div class="line"><a name="_a2"></a><a class="code" href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a> PS2Controller;</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// where to store WiFi info, etc...</span></div><div class="line">Preferences preferences;</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// copies embedded programs into SPIFFS/SDCard</span></div><div class="line"><span class="keywordtype">void</span> copyEmbeddedPrograms()</div><div class="line">{</div><div class="line">  <span class="keyword">auto</span> dir = FileBrowser();</div><div class="line">  dir.setDirectory(basepath);</div><div class="line">  <span class="keywordflow">if</span> (!dir.exists(EMBDIR, <span class="keyword">false</span>)) {</div><div class="line">    <span class="comment">// there isn&#39;t a EMBDIR folder, create and populate it</span></div><div class="line">    dir.makeDirectory(EMBDIR);</div><div class="line">    dir.changeDirectory(EMBDIR);</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(embeddedProgs) / <span class="keyword">sizeof</span>(EmbeddedProgDef); ++i) {</div><div class="line">      <span class="keywordtype">int</span> fullpathlen = dir.getFullPath(embeddedProgs[i].filename);</div><div class="line">      <span class="keywordtype">char</span> fullpath[fullpathlen];</div><div class="line">      dir.getFullPath(embeddedProgs[i].filename, fullpath, fullpathlen);</div><div class="line">      FILE * f = fopen(fullpath, <span class="stringliteral">&quot;wb&quot;</span>);</div><div class="line">      <span class="keywordflow">if</span> (f) {</div><div class="line">        fwrite(embeddedProgs[i].<a class="code" href="displaycontroller_8h_a96db82e580e46e24e2b39dd6c5bf7c21.html#a96db82e580e46e24e2b39dd6c5bf7c21">data</a>, 1, embeddedProgs[i].size, f);</div><div class="line">        fclose(f);</div><div class="line">      }</div><div class="line">    }</div><div class="line">  }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">enum</span> { STYLE_NONE, STYLE_LABEL, STYLE_LABELGROUP, STYLE_BUTTON, STYLE_BUTTONHELP, STYLE_COMBOBOX, STYLE_CHECKBOX, STYLE_FILEBROWSER};</div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#define BACKGROUND_COLOR RGB888(0, 0, 0)</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>DialogStyle : uiStyle {</div><div class="line">  <span class="keywordtype">void</span> setStyle(uiObject * <span class="keywordtype">object</span>, uint32_t styleClassID) {</div><div class="line">    <span class="keywordflow">switch</span> (styleClassID) {</div><div class="line">      <span class="keywordflow">case</span> STYLE_LABEL:</div><div class="line">        ((uiLabel*)<span class="keywordtype">object</span>)-&gt;labelStyle().textFont                           = &amp;fabgl::FONT_std_12;</div><div class="line">        ((uiLabel*)<span class="keywordtype">object</span>)-&gt;labelStyle().backgroundColor                    = BACKGROUND_COLOR;</div><div class="line">        ((uiLabel*)<span class="keywordtype">object</span>)-&gt;labelStyle().textColor                          = RGB888(255, 255, 255);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> STYLE_LABELGROUP:</div><div class="line">        ((uiLabel*)<span class="keywordtype">object</span>)-&gt;labelStyle().textFont                           = &amp;fabgl::FONT_std_12;</div><div class="line">        ((uiLabel*)<span class="keywordtype">object</span>)-&gt;labelStyle().backgroundColor                    = BACKGROUND_COLOR;</div><div class="line">        ((uiLabel*)<span class="keywordtype">object</span>)-&gt;labelStyle().textColor                          = RGB888(255, 128, 0);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> STYLE_BUTTON:</div><div class="line">        ((uiButton*)<span class="keywordtype">object</span>)-&gt;windowStyle().borderColor                      = RGB888(255, 255, 255);</div><div class="line">        ((uiButton*)<span class="keywordtype">object</span>)-&gt;buttonStyle().backgroundColor                  = RGB888(128, 128, 128);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> STYLE_BUTTONHELP:</div><div class="line">        ((uiButton*)<span class="keywordtype">object</span>)-&gt;windowStyle().borderColor                      = RGB888(255, 255, 255);</div><div class="line">        ((uiButton*)<span class="keywordtype">object</span>)-&gt;buttonStyle().backgroundColor                  = RGB888(255, 255, 128);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> STYLE_COMBOBOX:</div><div class="line">        ((uiFrame*)<span class="keywordtype">object</span>)-&gt;windowStyle().borderColor                       = RGB888(255, 255, 255);</div><div class="line">        ((uiFrame*)<span class="keywordtype">object</span>)-&gt;windowStyle().borderSize                        = 1;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> STYLE_CHECKBOX:</div><div class="line">        ((uiFrame*)<span class="keywordtype">object</span>)-&gt;windowStyle().borderColor                       = RGB888(255, 255, 255);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> STYLE_FILEBROWSER:</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;windowStyle().borderColor                     = RGB888(128, 128, 128);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;windowStyle().focusedBorderColor              = RGB888(255, 255, 255);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().backgroundColor                = RGB888(0, 255, 255);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().focusedBackgroundColor         = RGB888(0, 255, 255);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().selectedBackgroundColor        = RGB888(128, 64, 0);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().focusedSelectedBackgroundColor = RGB888(255, 128, 0);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().textColor                      = RGB888(0, 0, 128);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().selectedTextColor              = RGB888(0, 0, 255);</div><div class="line">        ((uiListBox*)<span class="keywordtype">object</span>)-&gt;listBoxStyle().textFont                       = &amp;fabgl::FONT_SLANT_8x14;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line">} dialogStyle;</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>DownloadProgressFrame : <span class="keyword">public</span> uiFrame {</div><div class="line"></div><div class="line">  uiLabel *  label1;</div><div class="line">  uiLabel *  label2;</div><div class="line">  uiButton * button;</div><div class="line"></div><div class="line">  DownloadProgressFrame(uiFrame * parent)</div><div class="line">    : uiFrame(parent, <span class="stringliteral">&quot;Download&quot;</span>, UIWINDOW_PARENTCENTER, Size(150, 110), false) {</div><div class="line">    frameProps().resizeable        = <span class="keyword">false</span>;</div><div class="line">    frameProps().moveable          = <span class="keyword">false</span>;</div><div class="line">    frameProps().hasCloseButton    = <span class="keyword">false</span>;</div><div class="line">    frameProps().hasMaximizeButton = <span class="keyword">false</span>;</div><div class="line">    frameProps().hasMinimizeButton = <span class="keyword">false</span>;</div><div class="line"></div><div class="line">    label1 = <span class="keyword">new</span> uiLabel(<span class="keyword">this</span>, <span class="stringliteral">&quot;Connecting...&quot;</span>, Point(10, 25));</div><div class="line">    label2 = <span class="keyword">new</span> uiLabel(<span class="keyword">this</span>, <span class="stringliteral">&quot;&quot;</span>, Point(10, 45));</div><div class="line">    button = <span class="keyword">new</span> uiButton(<span class="keyword">this</span>, <span class="stringliteral">&quot;Abort&quot;</span>, Point(50, 75), Size(50, 20));</div><div class="line">    button-&gt;onClick = [&amp;]() { exitModal(1); };</div><div class="line">  }</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>HelpFame : <span class="keyword">public</span> uiFrame {</div><div class="line"></div><div class="line">  HelpFame(uiFrame * parent)</div><div class="line">    : uiFrame(parent, <span class="stringliteral">&quot;Help&quot;</span>, UIWINDOW_PARENTCENTER, Size(218, 335), false) {</div><div class="line"></div><div class="line">    <span class="keyword">auto</span> button = <span class="keyword">new</span> uiButton(<span class="keyword">this</span>, <span class="stringliteral">&quot;OK&quot;</span>, Point(84, 305), Size(50, 20));</div><div class="line">    button-&gt;onClick = [&amp;]() { exitModal(0); };</div><div class="line"></div><div class="line">    onPaint = [&amp;]() {</div><div class="line">      <span class="keyword">auto</span> cv = canvas();</div><div class="line">      cv-&gt;selectFont(&amp;fabgl::FONT_6x8);</div><div class="line">      <span class="keywordtype">int</span> x = 4;</div><div class="line">      <span class="keywordtype">int</span> y = 10;</div><div class="line">      cv-&gt;setPenColor(<a name="a3"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cad0784a3f969fe736e8b271a5a161d106">Color::Green</a>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;Keyboard Shortcuts:&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a name="a4"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cac1e9bce8242f443c54c7405223d616cd">Color::Black</a>);</div><div class="line">      cv-&gt;setBrushColor(<a name="a5"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cab548046646b36c12aa6ba841de500094">Color::White</a>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  F12          &gt; Run or Config&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  DEL          &gt; Delete File/Folder&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  ALT + ASWZ   &gt; Move Screen&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a name="a6"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">Color::Blue</a>);</div><div class="line">      cv-&gt;drawText(x, y += 18, <span class="stringliteral">&quot;\&quot;None\&quot; Joystick Mode:&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cac1e9bce8242f443c54c7405223d616cd">Color::Black</a>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  ALT + MENU   &gt; Joystick Fire&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  ALT + CURSOR &gt; Joystick Move&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a name="a7"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cad3163c1fcda01965b692ec2c3122b743">Color::Red</a>);</div><div class="line">      cv-&gt;drawText(x, y += 18, <span class="stringliteral">&quot;\&quot;Cursor Keys\&quot; Joystick Mode:&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cac1e9bce8242f443c54c7405223d616cd">Color::Black</a>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  MENU         &gt; Joystick Fire&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  CURSOR       &gt; Joystick Move&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a name="a8"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cab5059a620e2c7dc57556b1e275c2f9bc">Color::Magenta</a>);</div><div class="line">      cv-&gt;drawText(x, y += 18, <span class="stringliteral">&quot;Emulated keyboard:&quot;</span>);</div><div class="line">      cv-&gt;setPenColor(<a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cac1e9bce8242f443c54c7405223d616cd">Color::Black</a>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  HOME         &gt; CLR/HOME&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  ESC          &gt; RUN/STOP&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  Left Win Key &gt; CBM&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  DELETE       &gt; RESTORE&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  BACKSPACE    &gt; INST/DEL&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  Caret ^      &gt; UP ARROW&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  Underscore _ &gt; LEFT ARROW&quot;</span>);</div><div class="line">      cv-&gt;drawText(x, y += 14, <span class="stringliteral">&quot;  Tilde ~      &gt; PI&quot;</span>);</div><div class="line">    };</div><div class="line">  }</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">class </span>Menu : <span class="keyword">public</span> uiApp {</div><div class="line"></div><div class="line">  uiFileBrowser * fileBrowser;</div><div class="line">  uiComboBox *    RAMExpComboBox;</div><div class="line">  uiComboBox *    kbdComboBox;</div><div class="line">  uiLabel *       freeSpaceLbl;</div><div class="line"></div><div class="line">  <span class="comment">// Main machine</span></div><div class="line">  Machine *       machine;</div><div class="line"></div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> init() {</div><div class="line">    machine = <span class="keyword">new</span> Machine(&amp;DisplayController);</div><div class="line"></div><div class="line">    setStyle(&amp;dialogStyle);</div><div class="line"></div><div class="line">    rootWindow()-&gt;frameStyle().backgroundColor = BACKGROUND_COLOR;</div><div class="line"></div><div class="line">    <span class="comment">// some static text</span></div><div class="line">    rootWindow()-&gt;onPaint = [&amp;]() {</div><div class="line">      <span class="keyword">auto</span> cv = canvas();</div><div class="line">      cv-&gt;selectFont(&amp;fabgl::FONT_SLANT_8x14);</div><div class="line">      cv-&gt;setPenColor(RGB888(0, 128, 255));</div><div class="line">      cv-&gt;drawText(136, 345, <span class="stringliteral">&quot;VIC20 Emulator&quot;</span>);</div><div class="line"></div><div class="line">      cv-&gt;selectFont(&amp;fabgl::FONT_std_12);</div><div class="line">      cv-&gt;setPenColor(RGB888(255, 128, 0));</div><div class="line">      cv-&gt;drawText(160, 358, <span class="stringliteral">&quot;www.fabgl.com&quot;</span>);</div><div class="line">      cv-&gt;drawText(130, 371, <span class="stringliteral">&quot;2019/21 by Fabrizio Di Vittorio&quot;</span>);</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// programs list</span></div><div class="line">    fileBrowser = <span class="keyword">new</span> uiFileBrowser(rootWindow(), Point(5, 10), Size(140, 290), <span class="keyword">true</span>, STYLE_FILEBROWSER);</div><div class="line">    fileBrowser-&gt;setDirectory(basepath);  <span class="comment">// set absolute path</span></div><div class="line">    fileBrowser-&gt;changeDirectory( fileBrowser-&gt;content().exists(DOWNDIR, <span class="keyword">false</span>) ? DOWNDIR : EMBDIR ); <span class="comment">// set relative path</span></div><div class="line">    fileBrowser-&gt;onChange = [&amp;]() {</div><div class="line">      setSelectedProgramConf();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// handles following keys:</span></div><div class="line">    <span class="comment">//  F1         -&gt;  show help</span></div><div class="line">    <span class="comment">//  ESC or F12 -&gt;  run the emulator</span></div><div class="line">    rootWindow()-&gt;onKeyUp = [&amp;](uiKeyEventInfo key) {</div><div class="line">      <span class="keywordflow">switch</span> (key.VK) {</div><div class="line">        <span class="comment">// F1</span></div><div class="line">        <span class="keywordflow">case</span> <a name="a9"></a><a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a50c8d8e7090ac699e7a411ace07d6e47">VirtualKey::VK_F1</a>:</div><div class="line">          showHelp();</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">        <span class="comment">// ESC or F12</span></div><div class="line">        <span class="keywordflow">case</span> <a name="a10"></a><a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a292abb1d79755a30f0316d7b13478f98">VirtualKey::VK_ESCAPE</a>:</div><div class="line">        <span class="keywordflow">case</span> <a name="a11"></a><a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a0587819039d24d9780c51ee62538e031">VirtualKey::VK_F12</a>:</div><div class="line">          runVIC20();</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">        <span class="comment">// just to avoid compiler warning</span></div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// handles following keys in filebrowser:</span></div><div class="line">    <span class="comment">//   RETURN -&gt; load selected program and return to vic</span></div><div class="line">    <span class="comment">//   DELETE -&gt; remove selected dir or file</span></div><div class="line">    fileBrowser-&gt;onKeyUp = [&amp;](uiKeyEventInfo key) {</div><div class="line">      <span class="keywordflow">switch</span> (key.VK) {</div><div class="line">        <span class="comment">// RETURN</span></div><div class="line">        <span class="keywordflow">case</span> <a name="a12"></a><a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a232f985e67663de971fe9d184e838a2b">VirtualKey::VK_RETURN</a>:</div><div class="line">          <span class="keywordflow">if</span> (!fileBrowser-&gt;isDirectory() &amp;&amp; loadSelectedProgram())</div><div class="line">            runVIC20();</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">        <span class="comment">// DELETE</span></div><div class="line">        <span class="keywordflow">case</span> <a name="a13"></a><a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02aa9d7938ace5b7bbf6d6774a7c970a8be">VirtualKey::VK_DELETE</a>:</div><div class="line">          <span class="keywordflow">if</span> (messageBox(<span class="stringliteral">&quot;Delete Item&quot;</span>, <span class="stringliteral">&quot;Are you sure?&quot;</span>, <span class="stringliteral">&quot;Yes&quot;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>) == uiMessageBoxResult::Button1) {</div><div class="line">            fileBrowser-&gt;content().remove( fileBrowser-&gt;filename() );</div><div class="line">            fileBrowser-&gt;update();</div><div class="line">            updateFreeSpaceLabel();</div><div class="line">          }</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">        <span class="comment">// just to avoid compiler warning</span></div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// handles double click on program list</span></div><div class="line">    fileBrowser-&gt;onDblClick = [&amp;]() {</div><div class="line">      <span class="keywordflow">if</span> (!fileBrowser-&gt;isDirectory() &amp;&amp; loadSelectedProgram())</div><div class="line">        runVIC20();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> x = 158;</div><div class="line"></div><div class="line">    <span class="comment">// &quot;Run&quot; button - run the VIC20</span></div><div class="line">    <span class="keyword">auto</span> VIC20Button = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;Run [F12]&quot;</span>, Point(x, 10), Size(75, 19), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTON);</div><div class="line">    VIC20Button-&gt;onClick = [&amp;]() {</div><div class="line">      runVIC20();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// &quot;Load&quot; button</span></div><div class="line">    <span class="keyword">auto</span> loadButton = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;Load&quot;</span>, Point(x, 35), Size(75, 19), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTON);</div><div class="line">    loadButton-&gt;onClick = [&amp;]() {</div><div class="line">      <span class="keywordflow">if</span> (loadSelectedProgram())</div><div class="line">        runVIC20();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// &quot;reset&quot; button</span></div><div class="line">    <span class="keyword">auto</span> resetButton = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;Soft Reset&quot;</span>, Point(x, 60), Size(75, 19), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTON);</div><div class="line">    resetButton-&gt;onClick = [&amp;]() {</div><div class="line">      machine-&gt;reset();</div><div class="line">      runVIC20();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// &quot;Hard Reset&quot; button</span></div><div class="line">    <span class="keyword">auto</span> hresetButton = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;Hard Reset&quot;</span>, Point(x, 85), Size(75, 19), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTON);</div><div class="line">    hresetButton-&gt;onClick = [&amp;]() {</div><div class="line">      machine-&gt;removeCRT();</div><div class="line">      machine-&gt;reset();</div><div class="line">      runVIC20();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// &quot;help&quot; button</span></div><div class="line">    <span class="keyword">auto</span> helpButton = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;HELP [F1]&quot;</span>, Point(x, 110), Size(75, 19), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTONHELP);</div><div class="line">    helpButton-&gt;onClick = [&amp;]() {</div><div class="line">      showHelp();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// select keyboard layout</span></div><div class="line">    <span class="keywordtype">int</span> y = 145;</div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;Keyboard Layout:&quot;</span>, Point(150, y), Size(0, 0), <span class="keyword">true</span>, STYLE_LABELGROUP);</div><div class="line">    kbdComboBox = <span class="keyword">new</span> uiComboBox(rootWindow(), Point(158, y + 20), Size(75, 20), 70, <span class="keyword">true</span>, STYLE_COMBOBOX);</div><div class="line">    kbdComboBox-&gt;items().append(SupportedLayouts::names(), SupportedLayouts::count());</div><div class="line">    kbdComboBox-&gt;onChange = [&amp;]() {</div><div class="line">      preferences.putInt(<span class="stringliteral">&quot;kbdLayout&quot;</span>, kbdComboBox-&gt;selectedItem());</div><div class="line">      updateKbdLayout();</div><div class="line">    };</div><div class="line">    kbdComboBox-&gt;selectItem(updateKbdLayout());</div><div class="line"></div><div class="line">    <span class="comment">// RAM expansion options</span></div><div class="line">    y += 50;</div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;RAM Expansion:&quot;</span>, Point(150, y), Size(0, 0), <span class="keyword">true</span>, STYLE_LABELGROUP);</div><div class="line">    RAMExpComboBox = <span class="keyword">new</span> uiComboBox(rootWindow(), Point(158, y + 20), Size(75, 19), 130, <span class="keyword">true</span>, STYLE_COMBOBOX);</div><div class="line">    <span class="keywordtype">char</span> <span class="keyword">const</span> * RAMOPTS[] = { <span class="stringliteral">&quot;Unexpanded&quot;</span>, <span class="stringliteral">&quot;3K&quot;</span>, <span class="stringliteral">&quot;8K&quot;</span>, <span class="stringliteral">&quot;16K&quot;</span>, <span class="stringliteral">&quot;24K&quot;</span>, <span class="stringliteral">&quot;27K (24K+3K)&quot;</span>, <span class="stringliteral">&quot;32K&quot;</span>, <span class="stringliteral">&quot;35K (32K+3K)&quot;</span> };</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8; ++i)</div><div class="line">      RAMExpComboBox-&gt;items().append(RAMOPTS[i]);</div><div class="line">    RAMExpComboBox-&gt;selectItem((<span class="keywordtype">int</span>)machine-&gt;RAMExpansion());</div><div class="line">    RAMExpComboBox-&gt;onChange = [&amp;]() {</div><div class="line">      machine-&gt;setRAMExpansion((RAMExpansionOption)(RAMExpComboBox-&gt;selectedItem()));</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// joystick emulation options</span></div><div class="line">    y += 50;</div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;Joystick:&quot;</span>, Point(150, y), Size(0, 0), <span class="keyword">true</span>, STYLE_LABELGROUP);</div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;None&quot;</span>, Point(180, y + 21), Size(0, 0), <span class="keyword">true</span>, STYLE_LABEL);</div><div class="line">    <span class="keyword">auto</span> radioJNone = <span class="keyword">new</span> uiCheckBox(rootWindow(), Point(158, y + 20), Size(16, 16), uiCheckBoxKind::RadioButton, <span class="keyword">true</span>, STYLE_CHECKBOX);</div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;Cursor Keys&quot;</span>, Point(180, y + 41), Size(0, 0), <span class="keyword">true</span>, STYLE_LABEL);</div><div class="line">    <span class="keyword">auto</span> radioJCurs = <span class="keyword">new</span> uiCheckBox(rootWindow(), Point(158, y + 40), Size(16, 16), uiCheckBoxKind::RadioButton, <span class="keyword">true</span>, STYLE_CHECKBOX);</div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;Mouse&quot;</span>, Point(180, y + 61), Size(0, 0), <span class="keyword">true</span>, STYLE_LABEL);</div><div class="line">    <span class="keyword">auto</span> radioJMous = <span class="keyword">new</span> uiCheckBox(rootWindow(), Point(158, y + 60), Size(16, 16), uiCheckBoxKind::RadioButton, <span class="keyword">true</span>, STYLE_CHECKBOX);</div><div class="line">    radioJNone-&gt;setGroupIndex(1);</div><div class="line">    radioJCurs-&gt;setGroupIndex(1);</div><div class="line">    radioJMous-&gt;setGroupIndex(1);</div><div class="line">    radioJNone-&gt;setChecked(machine-&gt;joyEmu() == JE_None);</div><div class="line">    radioJCurs-&gt;setChecked(machine-&gt;joyEmu() == JE_CursorKeys);</div><div class="line">    radioJMous-&gt;setChecked(machine-&gt;joyEmu() == JE_Mouse);</div><div class="line">    radioJNone-&gt;onChange = [&amp;]() { machine-&gt;setJoyEmu(JE_None); };</div><div class="line">    radioJCurs-&gt;onChange = [&amp;]() { machine-&gt;setJoyEmu(JE_CursorKeys); };</div><div class="line">    radioJMous-&gt;onChange = [&amp;]() { machine-&gt;setJoyEmu(JE_Mouse); };</div><div class="line"></div><div class="line">    <span class="comment">// free space label</span></div><div class="line">    freeSpaceLbl = <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;&quot;</span>, Point(5, 304), Size(0, 0), <span class="keyword">true</span>, STYLE_LABEL);</div><div class="line">    updateFreeSpaceLabel();</div><div class="line"></div><div class="line">    <span class="comment">// &quot;Download From&quot; label</span></div><div class="line">    <span class="keyword">new</span> uiLabel(rootWindow(), <span class="stringliteral">&quot;Download From:&quot;</span>, Point(5, 326), Size(0, 0), <span class="keyword">true</span>, STYLE_LABELGROUP);</div><div class="line"></div><div class="line">    <span class="comment">// Download List button (download programs listed and linked in LIST_URL)</span></div><div class="line">    <span class="keyword">auto</span> downloadProgsBtn = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;List&quot;</span>, Point(13, 345), Size(27, 20), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTON);</div><div class="line">    downloadProgsBtn-&gt;onClick = [&amp;]() {</div><div class="line">      <span class="keywordflow">if</span> (checkWiFi() &amp;&amp; messageBox(<span class="stringliteral">&quot;Download Programs listed in \&quot;LIST_URL\&quot;&quot;</span>, <span class="stringliteral">&quot;Check your local laws for restrictions&quot;</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>, <span class="keyword">nullptr</span>, uiMessageBoxIcon::Warning) == uiMessageBoxResult::Button1) {</div><div class="line">        <span class="keyword">auto</span> pframe = <span class="keyword">new</span> DownloadProgressFrame(rootWindow());</div><div class="line">        <span class="keyword">auto</span> modalStatus = initModalWindow(pframe);</div><div class="line">        processModalWindowEvents(modalStatus, 100);</div><div class="line">        prepareForDownload();</div><div class="line">        <span class="keywordtype">char</span> * list = downloadList();</div><div class="line">        <span class="keywordtype">char</span> * plist = list;</div><div class="line">        <span class="keywordtype">int</span> count = countListItems(list);</div><div class="line">        <span class="keywordtype">int</span> dcount = 0;</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; count; ++i) {</div><div class="line">          <span class="keywordtype">char</span> <span class="keyword">const</span> * filename;</div><div class="line">          <span class="keywordtype">char</span> <span class="keyword">const</span> * URL;</div><div class="line">          plist = getNextListItem(plist, &amp;filename, &amp;URL);</div><div class="line">          pframe-&gt;label1-&gt;setText(filename);</div><div class="line">          <span class="keywordflow">if</span> (!processModalWindowEvents(modalStatus, 100))</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">          <span class="keywordflow">if</span> (downloadURL(URL, filename))</div><div class="line">            ++dcount;</div><div class="line">          pframe-&gt;label2-&gt;setTextFmt(<span class="stringliteral">&quot;Downloaded %d/%d&quot;</span>, dcount, count);</div><div class="line">        }</div><div class="line">        free(list);</div><div class="line">        <span class="comment">// modify &quot;abort&quot; button to &quot;OK&quot;</span></div><div class="line">        pframe-&gt;button-&gt;setText(<span class="stringliteral">&quot;OK&quot;</span>);</div><div class="line">        pframe-&gt;button-&gt;repaint();</div><div class="line">        <span class="comment">// wait for OK</span></div><div class="line">        processModalWindowEvents(modalStatus, -1);</div><div class="line">        endModalWindow(modalStatus);</div><div class="line">        destroyWindow(pframe);</div><div class="line">        fileBrowser-&gt;update();</div><div class="line">        updateFreeSpaceLabel();</div><div class="line">      }</div><div class="line">      WiFi.disconnect();</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// Download from URL</span></div><div class="line">    <span class="keyword">auto</span> downloadURLBtn = <span class="keyword">new</span> uiButton(rootWindow(), <span class="stringliteral">&quot;URL&quot;</span>, Point(48, 345), Size(27, 20), uiButtonKind::Button, <span class="keyword">true</span>, STYLE_BUTTON);</div><div class="line">    downloadURLBtn-&gt;onClick = [&amp;]() {</div><div class="line">      <span class="keywordflow">if</span> (checkWiFi()) {</div><div class="line">        <span class="keywordtype">char</span> * URL = <span class="keyword">new</span> <span class="keywordtype">char</span>[128];</div><div class="line">        <span class="keywordtype">char</span> * filename = <span class="keyword">new</span> <span class="keywordtype">char</span>[25];</div><div class="line">        strcpy(URL, <span class="stringliteral">&quot;http://&quot;</span>);</div><div class="line">        <span class="keywordflow">if</span> (inputBox(<span class="stringliteral">&quot;Download From URL&quot;</span>, <span class="stringliteral">&quot;URL&quot;</span>, URL, 127, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>) == uiMessageBoxResult::Button1) {</div><div class="line">          <span class="keywordtype">char</span> * lastslash = strrchr(URL, <span class="charliteral">&#39;/&#39;</span>);</div><div class="line">          <span class="keywordflow">if</span> (lastslash) {</div><div class="line">            strcpy(filename, lastslash + 1);</div><div class="line">            <span class="keywordflow">if</span> (inputBox(<span class="stringliteral">&quot;Download From URL&quot;</span>, <span class="stringliteral">&quot;Filename&quot;</span>, filename, 24, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>) == uiMessageBoxResult::Button1) {</div><div class="line">              <span class="keywordflow">if</span> (downloadURL(URL, filename)) {</div><div class="line">                messageBox(<span class="stringliteral">&quot;Success&quot;</span>, <span class="stringliteral">&quot;Download OK!&quot;</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="keyword">nullptr</span>, <span class="keyword">nullptr</span>);</div><div class="line">                fileBrowser-&gt;update();</div><div class="line">                updateFreeSpaceLabel();</div><div class="line">              } <span class="keywordflow">else</span></div><div class="line">                messageBox(<span class="stringliteral">&quot;Error&quot;</span>, <span class="stringliteral">&quot;Download Failed!&quot;</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="keyword">nullptr</span>, <span class="keyword">nullptr</span>, uiMessageBoxIcon::Error);</div><div class="line">            }</div><div class="line">          }</div><div class="line">        }</div><div class="line">        <span class="keyword">delete</span> [] filename;</div><div class="line">        <span class="keyword">delete</span> [] URL;</div><div class="line">        WiFi.disconnect();</div><div class="line">      }</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">// focus on programs list</span></div><div class="line">    setFocusedWindow(fileBrowser);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// this is the main loop where 6502 instructions are executed until F12 has been pressed</span></div><div class="line">  <span class="keywordtype">void</span> runVIC20()</div><div class="line">  {</div><div class="line">    <span class="keyword">auto</span> keyboard = PS2Controller.<a name="a14"></a><a class="code" href="classfabgl_1_1_p_s2_controller_add3a17b29e9908b6e5cca6f52122119b.html#add3a17b29e9908b6e5cca6f52122119b">keyboard</a>();</div><div class="line"></div><div class="line">    enableKeyboardAndMouseEvents(<span class="keyword">false</span>);</div><div class="line">    keyboard-&gt;emptyVirtualKeyQueue();</div><div class="line">    machine-&gt;VIC().enableAudio(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">    <span class="comment">// setup user directory</span></div><div class="line">    machine-&gt;fileBrowser()-&gt;setDirectory(basepath);</div><div class="line">    <span class="keywordflow">if</span> (!machine-&gt;fileBrowser()-&gt;exists(USERDIR, <span class="keyword">false</span>))</div><div class="line">      machine-&gt;fileBrowser()-&gt;makeDirectory(USERDIR);</div><div class="line">    machine-&gt;fileBrowser()-&gt;changeDirectory(USERDIR);</div><div class="line"></div><div class="line">    <span class="keyword">auto</span> cv = canvas();</div><div class="line">    cv-&gt;setBrushColor(0, 0, 0);</div><div class="line">    cv-&gt;clear();</div><div class="line">    cv-&gt;waitCompletion();</div><div class="line"></div><div class="line">    <span class="keywordtype">bool</span> run = <span class="keyword">true</span>;</div><div class="line">    <span class="keywordflow">while</span> (run) {</div><div class="line"></div><div class="line"><span class="preprocessor">      #if DEBUGMACHINE</span></div><div class="line">        <span class="keywordtype">int</span> cycles = machine-&gt;run();</div><div class="line">        <span class="keywordflow">if</span> (restart) {</div><div class="line">          scycles = cycles;</div><div class="line">          restart = <span class="keyword">false</span>;</div><div class="line">        } <span class="keywordflow">else</span></div><div class="line">          scycles += cycles;</div><div class="line"><span class="preprocessor">      #else</span></div><div class="line">        machine-&gt;run();</div><div class="line"><span class="preprocessor">      #endif</span></div><div class="line"></div><div class="line">      <span class="comment">// read keyboard</span></div><div class="line">      <span class="keywordflow">if</span> (keyboard-&gt;virtualKeyAvailable()) {</div><div class="line">        <span class="keywordtype">bool</span> keyDown;</div><div class="line">        <a name="a15"></a><a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#gad0e6e31d5953384be4ea987eb3923e02">VirtualKey</a> vk = keyboard-&gt;getNextVirtualKey(&amp;keyDown);</div><div class="line">        <span class="keywordflow">switch</span> (vk) {</div><div class="line"></div><div class="line">          <span class="comment">// F12 - stop running</span></div><div class="line">          <span class="keywordflow">case</span> <a class="code" href="group___enumerations_gad0e6e31d5953384be4ea987eb3923e02.html#ggad0e6e31d5953384be4ea987eb3923e02a0587819039d24d9780c51ee62538e031">VirtualKey::VK_F12</a>:</div><div class="line">            <span class="keywordflow">if</span> (!keyDown)</div><div class="line">              run = <span class="keyword">false</span>;  <span class="comment">// exit loop</span></div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">          <span class="comment">// other keys</span></div><div class="line">          <span class="keywordflow">default</span>:</div><div class="line">            <span class="comment">// send to emulated machine</span></div><div class="line">            machine-&gt;setKeyboard(vk, keyDown);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">      }</div><div class="line"></div><div class="line">    }</div><div class="line">    machine-&gt;VIC().enableAudio(<span class="keyword">false</span>);</div><div class="line">    keyboard-&gt;emptyVirtualKeyQueue();</div><div class="line">    enableKeyboardAndMouseEvents(<span class="keyword">true</span>);</div><div class="line">    rootWindow()-&gt;repaint();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// extract required RAM size from selected filename (a space and 3K, 8K...)</span></div><div class="line">  <span class="keywordtype">void</span> setSelectedProgramConf()</div><div class="line">  {</div><div class="line">    <span class="keywordtype">char</span> <span class="keyword">const</span> * fname = fileBrowser-&gt;filename();</div><div class="line">    <span class="keywordflow">if</span> (fname) {</div><div class="line">      <span class="comment">// select required memory expansion</span></div><div class="line">      <span class="keyword">static</span> <span class="keywordtype">char</span> <span class="keyword">const</span> * EXP[8] = { <span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot; 3K&quot;</span>, <span class="stringliteral">&quot; 8K&quot;</span>, <span class="stringliteral">&quot; 16K&quot;</span>, <span class="stringliteral">&quot; 24K&quot;</span>, <span class="stringliteral">&quot; 27K&quot;</span>, <span class="stringliteral">&quot; 32K&quot;</span>, <span class="stringliteral">&quot; 35K&quot;</span> };</div><div class="line">      <span class="keywordtype">int</span> r = 0;</div><div class="line">      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i &lt; 8; ++i)</div><div class="line">        <span class="keywordflow">if</span> (strstr(fname, EXP[i])) {</div><div class="line">          r = i;</div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">      RAMExpComboBox-&gt;selectItem(r);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// extract address from selected filename. &quot;20&quot;=0x2000, &quot;40&quot;=0x4000, &quot;60&quot;=0x6000 or &quot;A0&quot;=0xA000, &quot;A0&quot; or automatic is the default</span></div><div class="line">  <span class="comment">// addrPos if specified will contain where address has been found</span></div><div class="line">  <span class="keywordtype">int</span> getAddress(<span class="keywordtype">char</span> * filename, <span class="keywordtype">char</span> * * addrPos = <span class="keyword">nullptr</span>)</div><div class="line">  {</div><div class="line">    <span class="keyword">static</span> <span class="keywordtype">char</span> <span class="keyword">const</span> * ASTR[] = { <span class="stringliteral">&quot; 20&quot;</span>, <span class="stringliteral">&quot; 40&quot;</span>, <span class="stringliteral">&quot; 60&quot;</span>, <span class="stringliteral">&quot; a0&quot;</span>, <span class="stringliteral">&quot; A0&quot;</span> };</div><div class="line">    <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span>    ADDR[] = { 0x2000, 0x4000, 0x6000, 0xa000, 0xa000 };</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(ADDR) / <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>); ++i) {</div><div class="line">      <span class="keyword">auto</span> p = strstr(filename, ASTR[i]);</div><div class="line">      <span class="keywordflow">if</span> (p) {</div><div class="line">        <span class="keywordflow">if</span> (addrPos)</div><div class="line">          *addrPos = p + 1;</div><div class="line">        <span class="keywordflow">return</span> ADDR[i];</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> -1;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// configuration given by filename:</span></div><div class="line">  <span class="comment">//    PROGNAME[EXP][ADDRESS].EXT</span></div><div class="line">  <span class="comment">//      PROGNAME : program name (not included extension)</span></div><div class="line">  <span class="comment">//      EXP      : expansion (&quot;3K&quot;, &quot;8K&quot;, &quot;16K&quot;, &quot;24K&quot;, &quot;27K&quot;, &quot;32K&quot;, &quot;35K&quot;)</span></div><div class="line">  <span class="comment">//      ADDRESS  : hex address (&quot;20&quot;=0x2000, &quot;40&quot;=0x4000, &quot;60&quot;=0x6000 or &quot;A0&quot;=0xA000), &quot;A0&quot; or automatic is the default</span></div><div class="line">  <span class="comment">//      EXT      : &quot;CRT&quot; or &quot;PRG&quot;</span></div><div class="line">  <span class="keywordtype">bool</span> loadSelectedProgram()</div><div class="line">  {</div><div class="line">    <span class="keywordtype">bool</span> backToVIC = <span class="keyword">false</span>;</div><div class="line">    <span class="keywordtype">char</span> <span class="keyword">const</span> * fname = fileBrowser-&gt;filename();</div><div class="line">    <span class="keywordflow">if</span> (fname) {</div><div class="line">      FileBrowser &amp; dir  = fileBrowser-&gt;content();</div><div class="line"></div><div class="line">      <span class="keywordtype">bool</span> isPRG = strstr(fname, <span class="stringliteral">&quot;.PRG&quot;</span>) || strstr(fname, <span class="stringliteral">&quot;.prg&quot;</span>);</div><div class="line">      <span class="keywordtype">bool</span> isCRT = strstr(fname, <span class="stringliteral">&quot;.CRT&quot;</span>) || strstr(fname, <span class="stringliteral">&quot;.crt&quot;</span>);</div><div class="line"></div><div class="line">      <span class="keywordflow">if</span> (isPRG || isCRT) {</div><div class="line"></div><div class="line">        machine-&gt;removeCRT();</div><div class="line"></div><div class="line">        <span class="keywordtype">int</span> fullpathlen = dir.getFullPath(fname);</div><div class="line">        <span class="keywordtype">char</span> fullpath[fullpathlen];</div><div class="line">        dir.getFullPath(fname, fullpath, fullpathlen);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (isPRG) {</div><div class="line">          <span class="comment">// this is a PRG, just reset, load and run</span></div><div class="line">          machine-&gt;loadPRG(fullpath, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line">        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (isCRT) {</div><div class="line">          <span class="comment">// this a CRT, find other parts, load and reset</span></div><div class="line">          <span class="keywordtype">char</span> * addrPos = <span class="keyword">nullptr</span>;</div><div class="line">          <span class="keywordtype">int</span> addr = getAddress(fullpath, &amp;addrPos);</div><div class="line">          <span class="keywordflow">if</span> (addrPos) {</div><div class="line">            <span class="comment">// address specified, try to load all possible positions (2000, 4000, 6000 and a000)</span></div><div class="line">            <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * POS = { <span class="stringliteral">&quot;246Aa&quot;</span> }; <span class="comment">// 2=2000, 4=4000, 6=6000, A=a000</span></div><div class="line">            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(POS); ++i) {</div><div class="line">              *addrPos = POS[i];  <span class="comment">// actually replaces char inside &quot;fullpath&quot;</span></div><div class="line">              machine-&gt;loadCRT(fullpath, <span class="keyword">true</span>, getAddress(fullpath));</div><div class="line">            }</div><div class="line">          } <span class="keywordflow">else</span> {</div><div class="line">            <span class="comment">// no address specified, just load it</span></div><div class="line">            machine-&gt;loadCRT(fullpath, <span class="keyword">true</span>, addr);</div><div class="line">          }</div><div class="line">        }</div><div class="line">        backToVIC = <span class="keyword">true</span>;</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> backToVIC;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// true if WiFi is has been connected</span></div><div class="line">  <span class="keywordtype">bool</span> checkWiFi() {</div><div class="line">    <span class="keywordflow">if</span> (WiFi.status() == WL_CONNECTED)</div><div class="line">      <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">    <span class="keywordtype">char</span> SSID[32] = <span class="stringliteral">&quot;&quot;</span>;</div><div class="line">    <span class="keywordtype">char</span> psw[32]  = <span class="stringliteral">&quot;&quot;</span>;</div><div class="line">    <span class="keywordflow">if</span> (!preferences.getString(<span class="stringliteral">&quot;SSID&quot;</span>, SSID, <span class="keyword">sizeof</span>(SSID)) || !preferences.getString(<span class="stringliteral">&quot;WiFiPsw&quot;</span>, psw, <span class="keyword">sizeof</span>(psw))) {</div><div class="line">      <span class="comment">// ask user for SSID and password</span></div><div class="line">      <span class="keywordflow">if</span> (inputBox(<span class="stringliteral">&quot;WiFi Connect&quot;</span>, <span class="stringliteral">&quot;WiFi Name&quot;</span>, SSID, <span class="keyword">sizeof</span>(SSID), <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>) == uiMessageBoxResult::Button1 &amp;&amp;</div><div class="line">          inputBox(<span class="stringliteral">&quot;WiFi Connect&quot;</span>, <span class="stringliteral">&quot;Password&quot;</span>, psw, <span class="keyword">sizeof</span>(psw), <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>) == uiMessageBoxResult::Button1) {</div><div class="line">        preferences.putString(<span class="stringliteral">&quot;SSID&quot;</span>, SSID);</div><div class="line">        preferences.putString(<span class="stringliteral">&quot;WiFiPsw&quot;</span>, psw);</div><div class="line">      } <span class="keywordflow">else</span></div><div class="line">        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">    }</div><div class="line">    WiFi.begin(SSID, psw);</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 2 &amp;&amp; WiFi.status() != WL_CONNECTED; ++i) {</div><div class="line">      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; 16 &amp;&amp; WiFi.status() != WL_CONNECTED; ++j)</div><div class="line">        delay(1000);</div><div class="line">      WiFi.reconnect();</div><div class="line">    }</div><div class="line">    <span class="keywordtype">bool</span> connected = (WiFi.status() == WL_CONNECTED);</div><div class="line">    <span class="keywordflow">if</span> (!connected) {</div><div class="line">      messageBox(<span class="stringliteral">&quot;Network Error&quot;</span>, <span class="stringliteral">&quot;Failed to connect WiFi. Try again!&quot;</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="keyword">nullptr</span>, <span class="keyword">nullptr</span>, uiMessageBoxIcon::Error);</div><div class="line">      preferences.remove(<span class="stringliteral">&quot;WiFiPsw&quot;</span>);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> connected;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// creates List folder and makes it current</span></div><div class="line">  <span class="keywordtype">void</span> prepareForDownload()</div><div class="line">  {</div><div class="line">    FileBrowser &amp; dir = fileBrowser-&gt;content();</div><div class="line">    dir.setDirectory(basepath);</div><div class="line">    dir.makeDirectory(DOWNDIR);</div><div class="line">    dir.changeDirectory(DOWNDIR);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// download list from LIST_URL</span></div><div class="line">  <span class="comment">// ret nullptr on fail</span></div><div class="line">  <span class="keywordtype">char</span> * downloadList()</div><div class="line">  {</div><div class="line">    <span class="keyword">auto</span> list = (<span class="keywordtype">char</span>*) malloc(MAXLISTSIZE);</div><div class="line">    <span class="keyword">auto</span> dest = list;</div><div class="line">    HTTPClient http;</div><div class="line">    http.begin(LIST_URL);</div><div class="line">    <span class="keywordtype">int</span> httpCode = http.GET();</div><div class="line">    <span class="keywordflow">if</span> (httpCode == HTTP_CODE_OK) {</div><div class="line">      WiFiClient * stream = http.getStreamPtr();</div><div class="line">      <span class="keywordtype">int</span> bufspace = MAXLISTSIZE;</div><div class="line">      <span class="keywordflow">while</span> (http.connected() &amp;&amp; bufspace &gt; 1) {</div><div class="line">        <span class="keyword">auto</span> size = stream-&gt;available();</div><div class="line">        <span class="keywordflow">if</span> (size) {</div><div class="line">          <span class="keywordtype">int</span> c = stream-&gt;readBytes(dest, fabgl::imin(bufspace, size));</div><div class="line">          dest += c;</div><div class="line">          bufspace -= c;</div><div class="line">        } <span class="keywordflow">else</span></div><div class="line">          <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">    }</div><div class="line">    *dest = 0;</div><div class="line">    <span class="keywordflow">return</span> list;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// count number of items in download list</span></div><div class="line">  <span class="keywordtype">int</span> countListItems(<span class="keywordtype">char</span> <span class="keyword">const</span> * list)</div><div class="line">  {</div><div class="line">    <span class="keywordtype">int</span> count = 0;</div><div class="line">    <span class="keyword">auto</span> p = list;</div><div class="line">    <span class="keywordflow">while</span> (*p++)</div><div class="line">      <span class="keywordflow">if</span> (*p == 0x0a)</div><div class="line">        ++count;</div><div class="line">    <span class="keywordflow">return</span> (count + 1) / 3;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// extract filename and URL from downloaded list</span></div><div class="line">  <span class="keywordtype">char</span> * getNextListItem(<span class="keywordtype">char</span> * list, <span class="keywordtype">char</span> <span class="keyword">const</span> * * filename, <span class="keywordtype">char</span> <span class="keyword">const</span> * * URL)</div><div class="line">  {</div><div class="line">    <span class="comment">// bypass spaces</span></div><div class="line">    <span class="keywordflow">while</span> (*list == 0x0a || *list == 0x0d || *list == 0x20)</div><div class="line">      ++list;</div><div class="line">    <span class="comment">// get filename</span></div><div class="line">    *filename = list;</div><div class="line">    <span class="keywordflow">while</span> (*list &amp;&amp; *list != 0x0a &amp;&amp; *list != 0x0d)</div><div class="line">      ++list;</div><div class="line">    *list++ = 0;</div><div class="line">    <span class="comment">// bypass spaces</span></div><div class="line">    <span class="keywordflow">while</span> (*list &amp;&amp; (*list == 0x0a || *list == 0x0d || *list == 0x20))</div><div class="line">      ++list;</div><div class="line">    <span class="comment">// get URL</span></div><div class="line">    *URL = list;</div><div class="line">    <span class="keywordflow">while</span> (*list &amp;&amp; *list != 0x0a &amp;&amp; *list != 0x0d)</div><div class="line">      ++list;</div><div class="line">    *list++ = 0;</div><div class="line">    <span class="keywordflow">return</span> list;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// download specified filename from URL</span></div><div class="line">  <span class="keywordtype">bool</span> downloadURL(<span class="keywordtype">char</span> <span class="keyword">const</span> * URL, <span class="keywordtype">char</span> <span class="keyword">const</span> * filename)</div><div class="line">  {</div><div class="line">    FileBrowser &amp; dir = fileBrowser-&gt;content();</div><div class="line">    <span class="keywordflow">if</span> (dir.exists(filename, <span class="keyword">false</span>)) {</div><div class="line">      <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">    }</div><div class="line">    <span class="keywordtype">bool</span> success = <span class="keyword">false</span>;</div><div class="line">    HTTPClient http;</div><div class="line">    http.begin(URL);</div><div class="line">    <span class="keywordtype">int</span> httpCode = http.GET();</div><div class="line">    <span class="keywordflow">if</span> (httpCode == HTTP_CODE_OK) {</div><div class="line"></div><div class="line">      <span class="keywordtype">int</span> fullpathLen = dir.getFullPath(filename);</div><div class="line">      <span class="keywordtype">char</span> fullpath[fullpathLen];</div><div class="line">      dir.getFullPath(filename, fullpath, fullpathLen);</div><div class="line">      FILE * f = fopen(fullpath, <span class="stringliteral">&quot;wb&quot;</span>);</div><div class="line"></div><div class="line">      <span class="keywordflow">if</span> (f) {</div><div class="line">        <span class="keywordtype">int</span> len = http.getSize();</div><div class="line">        constexpr <span class="keywordtype">int</span> BUFSIZE = 1024;</div><div class="line">        uint8_t * buf = (uint8_t*) malloc(BUFSIZE);</div><div class="line">        WiFiClient * stream = http.getStreamPtr();</div><div class="line">        <span class="keywordtype">int</span> dsize = 0;</div><div class="line">        <span class="keywordflow">while</span> (http.connected() &amp;&amp; (len &gt; 0 || len == -1)) {</div><div class="line">          <span class="keywordtype">size_t</span> size = stream-&gt;available();</div><div class="line">          <span class="keywordflow">if</span> (size) {</div><div class="line">            <span class="keywordtype">int</span> c = stream-&gt;readBytes(buf, fabgl::imin(BUFSIZE, size));</div><div class="line">            fwrite(buf, c, 1, f);</div><div class="line">            dsize += c;</div><div class="line">            <span class="keywordflow">if</span> (len &gt; 0)</div><div class="line">              len -= c;</div><div class="line">          }</div><div class="line">        }</div><div class="line">        free(buf);</div><div class="line">        fclose(f);</div><div class="line">        success = (len == 0 || (len == -1 &amp;&amp; dsize &gt; 0));</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> success;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// show free SPIFFS space</span></div><div class="line">  <span class="keywordtype">void</span> updateFreeSpaceLabel() {</div><div class="line">    int64_t total, used;</div><div class="line">    FileBrowser::getFSInfo(fileBrowser-&gt;content().getCurrentDriveType(), 0, &amp;total, &amp;used);</div><div class="line">    freeSpaceLbl-&gt;setTextFmt(<span class="stringliteral">&quot;%lld KiB Free&quot;</span>, (total - used) / 1024);</div><div class="line">    freeSpaceLbl-&gt;update();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">int</span> updateKbdLayout() {</div><div class="line">    <span class="keyword">auto</span> curLayoutIdx = preferences.getInt(<span class="stringliteral">&quot;kbdLayout&quot;</span>, 3); <span class="comment">// default US</span></div><div class="line">    PS2Controller.<a class="code" href="classfabgl_1_1_p_s2_controller_add3a17b29e9908b6e5cca6f52122119b.html#add3a17b29e9908b6e5cca6f52122119b">keyboard</a>()-&gt;<a name="a16"></a><a class="code" href="classfabgl_1_1_keyboard_aca97a7179d5358ec795485e15618b243.html#aca97a7179d5358ec795485e15618b243">setLayout</a>(SupportedLayouts::layouts()[curLayoutIdx]);</div><div class="line">    <span class="keywordflow">return</span> curLayoutIdx;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> showHelp() {</div><div class="line">    <span class="keyword">auto</span> hframe = <span class="keyword">new</span> HelpFame(rootWindow());</div><div class="line">    showModalWindow(hframe);</div><div class="line">    destroyWindow(hframe);</div><div class="line">  }</div><div class="line"></div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line"><span class="preprocessor">  #if DEBUG</span></div><div class="line">  Serial.begin(115200); delay(500); Serial.write(<span class="stringliteral">&quot;\n\n\nReset\n&quot;</span>); <span class="comment">// for debug purposes</span></div><div class="line"><span class="preprocessor">  #endif</span></div><div class="line"></div><div class="line">  preferences.begin(<span class="stringliteral">&quot;VIC20&quot;</span>, <span class="keyword">false</span>);</div><div class="line">  <span class="comment">//preferences.clear();</span></div><div class="line"></div><div class="line">  PS2Controller.<a name="a17"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">begin</a>(PS2Preset::KeyboardPort0_MousePort1, KbdMode::CreateVirtualKeysQueue);</div><div class="line"></div><div class="line">  DisplayController.begin();</div><div class="line">  DisplayController.<a name="a18"></a>setResolution(<a name="a19"></a><a class="code" href="fabglconf_8h_a79c16e345febd0d26723e122a4b939b4.html#a79c16e345febd0d26723e122a4b939b4">VGA_256x384_60Hz</a>);</div><div class="line"></div><div class="line">  <span class="comment">// this improves user interface speed - check possible drawbacks before enabling definitively</span></div><div class="line">  <span class="comment">//DisplayController.enableBackgroundPrimitiveExecution(false);</span></div><div class="line"></div><div class="line">  <span class="comment">// adjust this to center screen in your monitor</span></div><div class="line">  <span class="comment">//DisplayController.moveScreen(20, -2);</span></div><div class="line"></div><div class="line">  Canvas cv(&amp;DisplayController);</div><div class="line">  cv.selectFont(&amp;fabgl::FONT_6x8);</div><div class="line"></div><div class="line">  cv.clear();</div><div class="line">  cv.drawText(25, 10, <span class="stringliteral">&quot;Initializing...&quot;</span>);</div><div class="line">  cv.waitCompletion();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (FileBrowser::mountSDCard(FORMAT_ON_FAIL, SDCARD_MOUNT_PATH))</div><div class="line">    basepath = SDCARD_MOUNT_PATH;</div><div class="line">  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (FileBrowser::mountSPIFFS(FORMAT_ON_FAIL, SPIFFS_MOUNT_PATH))</div><div class="line">    basepath = SPIFFS_MOUNT_PATH;</div><div class="line"></div><div class="line">  cv.drawText(25, 30, <span class="stringliteral">&quot;Copying embedded programs...&quot;</span>);</div><div class="line">  cv.waitCompletion();</div><div class="line">  copyEmbeddedPrograms();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line"><span class="preprocessor">  #if DEBUGMACHINE</span></div><div class="line">  TimerHandle_t xtimer = xTimerCreate(<span class="stringliteral">&quot;&quot;</span>, pdMS_TO_TICKS(5000), pdTRUE, (<span class="keywordtype">void</span>*)0, vTimerCallback1SecExpired);</div><div class="line">  xTimerStart(xtimer, 0);</div><div class="line"><span class="preprocessor">  #endif</span></div><div class="line"></div><div class="line">  <span class="keyword">auto</span> menu = <span class="keyword">new</span> Menu;</div><div class="line">  menu-&gt;run(&amp;DisplayController);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 2 2021 07:08:02 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
